from django.shortcuts import render
from rest_framework import viewsets
from rest_framework import permissions
from certificate_manager.models import *
from certificate_manager.serializers import *
from rest_framework.decorators import api_view
from rest_framework.response import Response
from certificate_manager.permissions import ReadOnly

class UserTagViewSet(viewsets.ModelViewSet):
    queryset = UserTag.objects.all()
    serializer_class = UserTagSerializer 
    permission_classes = [permissions.IsAdminUser|ReadOnly]

    def list(self, request):
        param = request.query_params
        # 现在我们要从里面拿出name属性
        if 'name' in param:
            name = param['name']
            user_tag = UserTag.objects.filter(name__contains=name)
            return Response(UserTagSerializer(user_tag, many=True).data)

        return super().list(request)
